﻿@model ProductOverviewModel
@{
    //prepare "Add to cart" AJAX link
    string addtocartlink = "";
    string addtowishlistlink = "";
    string quickviewurl = Url.RouteUrl("QuickView-Product", new { productId = Model.Id });

    var shoppingCartTypeId = (int)ShoppingCartType.ShoppingCart;
    var quantity = 1;
    if (!Model.ShowQty)
    {
        if (Model.ProductPrice.ForceRedirectionAfterAddingToCart)
        {
            addtocartlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.Id, shoppingCartTypeId = shoppingCartTypeId, quantity = quantity, forceredirection = Model.ProductPrice.ForceRedirectionAfterAddingToCart });
        }
        else
        {
            addtocartlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.Id, shoppingCartTypeId = shoppingCartTypeId, quantity = quantity });
        }
        addtowishlistlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.Id, shoppingCartTypeId = (int)ShoppingCartType.Wishlist, quantity = quantity });
    }
    else
    {
        if (Model.ProductPrice.ForceRedirectionAfterAddingToCart)
        {
            addtocartlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.Id, shoppingCartTypeId = shoppingCartTypeId, forceredirection = Model.ProductPrice.ForceRedirectionAfterAddingToCart });
        }
        else
        {
            addtocartlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.Id, shoppingCartTypeId = shoppingCartTypeId });
        }
        addtowishlistlink = Url.RouteUrl("AddProductToCart-Catalog", new { productId = Model.Id, shoppingCartTypeId = (int)ShoppingCartType.Wishlist });
    }
    var addtocomparelink = Url.RouteUrl("AddProductToCompare", new { productId = Model.Id });
}

@await Component.InvokeAsync("Widget", new { widgetZone = "productbox_featured_before_content", additionalData = Model })

<div class="card product-box rowHelper col-12 p-0 mb-0 featured-product" data-productid="@Model.Id">
    <div class="prod-list">
        <a href="@Url.RouteUrl("Product", new { SeName = Model.SeName })" title="@Model.DefaultPictureModel.Title">
            <picture>
                <source media="(max-width: 480px)" picture-id="@Model.DefaultPictureModel.Id" picture-size="200" />
                <img class="img-fluid" alt="@Model.DefaultPictureModel.AlternateText" src="@Model.DefaultPictureModel.ImageUrl" title="@Model.DefaultPictureModel.Title"
                     @if (!string.IsNullOrEmpty(Model.SecondPictureModel.ImageUrl)) { <text>
                     onmouseover="this.src='@Model.SecondPictureModel.ImageUrl';" onmouseout="this.src='@Model.DefaultPictureModel.ImageUrl';"
                     </text> } />
            </picture>
        </a>
        <div class="labels">
            @if (!String.IsNullOrEmpty(Model.ProductPrice.OldPrice))
            {
                <span class="product-discount badge product-box-label">
                    <span>-@(Convert.ToInt32((1 - Model.ProductPrice.PriceValue / Model.ProductPrice.OldPriceValue) * 100))%</span>
                </span>
            }
            @if (!string.IsNullOrEmpty(Model.Flag))
            {
                <span class="product-box-label badge bg-info text-white">@Model.Flag</span>
            }
        </div>
        <div class="card-body px-2 text-left">
            <h5 class="card-title mt-0">
                <strong><a href="@Url.RouteUrl("Product", new { SeName = Model.SeName })">@Model.Name</a></strong>
                @if (Model.ShowSku && !string.IsNullOrEmpty(Model.Sku))
                {
                    <span class="d-block py-1">@Model.Sku</span>
                }
            </h5>
            @if (Model.ReviewOverviewModel.AllowCustomerReviews)
            {
                int ratingPercent = 0;
                if (Model.ReviewOverviewModel.TotalReviews != 0)
                {
                    ratingPercent = ((Model.ReviewOverviewModel.RatingSum * 100) / Model.ReviewOverviewModel.TotalReviews) / 5;
                }
                <div class="ratings justify-content-start">
                    <div class="rating-box">
                        <div class="rating" style="width: @(ratingPercent)%">
                        </div>
                    </div>
                </div>
            }
            @await Component.InvokeAsync("Widget", new { widgetZone = "productbox_addinfo_before", additionalData = Model.Id })
            <ul class="d-inline-flex align-items-center flex-wrap pl-0 mb-0">

                @if (!String.IsNullOrEmpty(Model.ProductPrice.OldPrice))
                {
                    <li class="d-inline-flex">
                        <span class="price old-price">@Model.ProductPrice.OldPrice</span>
                    </li>
                }
                @if (Model.ProductType != ProductType.Auction)
                {
                    <li class="price actual-price d-inline-flex">@Model.ProductPrice.Price</li>
                }
                else
                {
                    <li class="price actual-price d-inline-flex">@(Model.ProductPrice.HighestBidValue > 0 ? Model.ProductPrice.HighestBid : Model.ProductPrice.StartPrice)</li>
                }

                @if (!String.IsNullOrEmpty(Model.ProductPrice.BasePricePAngV))
                {
                    <li class="base-price-pangv">
                        @Model.ProductPrice.BasePricePAngV
                    </li>
                }

            </ul>
            @if (Model.ProductPrice.DisplayTaxShippingInfo)
            {
                var inclTax = Model.TaxDisplayType == TaxDisplayType.IncludingTax;
                //tax info is already included in the price (incl/excl tax). that's why we display only shipping info here
                //of course, you can modify appropriate locales to include VAT info there
                <div class="tax-shipping-info">
                    @T(inclTax ? "Products.Price.TaxShipping.InclTax" : "Products.Price.TaxShipping.ExclTax", Url.RouteUrl("Topic", new { SeName = await Html.GetTopicSeName("shippinginfo", Context) }))
                </div>
            }
            @await Component.InvokeAsync("Widget", new { widgetZone = "productbox_addinfo_middle", additionalData = Model.Id })
            @await Component.InvokeAsync("Widget", new { widgetZone = "productbox_addinfo_after", additionalData = Model.Id })
        </div>
    </div>
</div>
